package com.zhl.gradledemo.service.impl;

import com.zhl.gradledemo.dao.BaseDao;
import com.zhl.gradledemo.mapper.BrokerMessageLogMapper;
import com.zhl.gradledemo.model.BrokerMessageLog;
import com.zhl.gradledemo.service.BrokerMessageLogService;
import com.zhl.gradledemo.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2019/11/2.
 */
@Service
@Transactional
public class BrokerMessageLogServiceImpl extends BaseServiceImpl<BrokerMessageLog> implements BrokerMessageLogService {

    @Resource
    private BrokerMessageLogMapper brokerMessageLogMapper;

    @Override
    protected BaseDao<BrokerMessageLog> getBaseDao() {
        return brokerMessageLogMapper;
    }

    @Override
    public List<BrokerMessageLog> query4StatusAndTimeoutMessage() {

        List<BrokerMessageLog> brokerMessageLogList = brokerMessageLogMapper.query4StatusAndTimeoutMessage();

        return brokerMessageLogList;
    }

    @Override
    public void changeBrokerMessageLogStatus(String messageId, String status) {
        Example example = new Example(BrokerMessageLog.class);
        example.createCriteria().andEqualTo("messageId",messageId);
        BrokerMessageLog brokerMessageLog = brokerMessageLogMapper.selectOneByExample(example);
        brokerMessageLog.setStatus(status);
        brokerMessageLog.setUpdateTime(new Date());

        this.update(brokerMessageLog);
    }
}
